//
//  HNSH_CancellationViewController.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/6/26.
//

#import "HNSH_CancellationViewController.h"

#import "HNSH_AlertView.h"
#import "HNSH_GetAuthCodeAlert.h"

@interface HNSH_CancellationViewController ()

@end

@implementation HNSH_CancellationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self showNavTitle:@"注销" showLeftItem:YES];
    
    [self configUI];
    
    [self configBottomView];
}

- (void)configUI {
    UILabel *titleLabel1 = [[UILabel alloc]init];
    titleLabel1.text = @"注销前提条件";
    titleLabel1.textColor = [UIColor appBlackLabelColor];
    titleLabel1.font = [UIFont boldSystemFontOfSize:16];
    [self.view addSubview:titleLabel1];
    
    UILabel *desLabel1 = [[UILabel alloc]init];
    desLabel1.text = @"1.账号下有粉丝，不支持注销操作";
    desLabel1.textColor = [UIColor appGrayLabelColor];
    desLabel1.font = [UIFont systemFontOfSize:14];
    desLabel1.numberOfLines = 0;
    [self.view addSubview:desLabel1];
    
    [titleLabel1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(16+kNavBarAndStatusBarHeight);
        make.left.mas_equalTo(16);
        make.height.mas_equalTo(22);
    }];
    
    [desLabel1 setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];
    [desLabel1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-16);
        make.left.mas_equalTo(16);
        make.top.equalTo(titleLabel1.mas_bottom).offset(4);
    }];
    
    
    UILabel *titleLabel2 = [[UILabel alloc]init];
    titleLabel2.text = @"注销后将失去以下权益";
    titleLabel2.textColor = [UIColor appBlackLabelColor];
    titleLabel2.font = [UIFont boldSystemFontOfSize:16];
    [self.view addSubview:titleLabel2];
    
    UILabel *desLabel2 = [[UILabel alloc]init];
    desLabel2.text = @"1..身份、账号信息将会被清空且无法恢复，无法再使用手机号、微信号等进行登录。\n2.账号内已获得的绿色能量、通证等将被清空且无法恢复。\n3.注销成功后，已完成的交易，无法享受售后服务。\n4.注销成功后，同一手机号不支持重新注册。";
    desLabel2.textColor = [UIColor appGrayLabelColor];
    desLabel2.font = [UIFont systemFontOfSize:14];
    desLabel2.numberOfLines = 0;
    [self.view addSubview:desLabel2];
    
    [titleLabel2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(desLabel1.mas_bottom).offset(16);
        make.left.mas_equalTo(16);
        make.height.mas_equalTo(22);
    }];
    
    [desLabel2 setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];
    [desLabel2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-16);
        make.left.mas_equalTo(16);
        make.top.equalTo(titleLabel2.mas_bottom).offset(4);
    }];
}

- (void)configBottomView {
    UIView *bottomView = [[UIView alloc]init];
    bottomView.backgroundColor = [UIColor appWhiteLabelColor];
    [self.view addSubview:bottomView];
    [bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(0);
        make.height.mas_equalTo(114+kBottomSafeHeight);
    }];
    
    UIButton *selectButton = [UIButton buttonWithType:UIButtonTypeCustom];
    selectButton.frame = CGRectMake(16, 18, 16, 16);
    [selectButton setImage:[UIImage imageNamed:@"base_select_off"] forState:UIControlStateNormal];
    [selectButton setImage:[UIImage imageNamed:@"base_select_on"] forState:UIControlStateSelected];
    [bottomView addSubview:selectButton];
    [[selectButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        UIButton *button = x;
        button.selected = !button.selected;
    }];
    
    UILabel *desLabel1 = [[UILabel alloc]initWithFrame:CGRectMake(40, 16, 300, 20)];
    desLabel1.text = @"我已阅读并同意上述内容，点击进行注销";
    desLabel1.textColor = [UIColor appBlackLabelColor];
    desLabel1.font = [UIFont systemFontOfSize:14];
    [bottomView addSubview:desLabel1];
    
    
    UIButton *submitButton = [UIButton buttonWithType:UIButtonTypeCustom];
    submitButton.frame = CGRectMake(16, 58, kScreenWidth-32, 44);
    [submitButton setTitle:@"注销账号" forState:UIControlStateNormal];
    [submitButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    submitButton.titleLabel.font = [UIFont systemFontOfSize:16];
    submitButton.layer.cornerRadius = 22;
    submitButton.layer.masksToBounds = YES;
    submitButton.backgroundColor = [UIColor appGreenColor];
    [bottomView addSubview:submitButton];
    __weak __typeof(&*self)weakSelf = self;
    [[submitButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        if (!selectButton.isSelected) {
            [weakSelf.view makeToast:@"请同意上述内容"];
            return;
        }
        
        [HNSH_UserNetServer requestUserCancellationWithForce:0 sms_code:@"" success:^(ST_BaseNetModel * _Nullable responseObject) {
            if (responseObject.code == 960) {//您的账号下有粉丝存在，不可注销
                [HNSH_AlertView showTitle:responseObject.msg des:@"" buttonTitle:@"确定" buttonColor:[UIColor appGreenColor] buttonClick:^{
                    
                }];
            } else if (responseObject.code == 962 || responseObject.code == 961) {//账户一经注销，不可找回，不可重新注册，是否要进行注销？（无资金弹窗）
                [HNSH_AlertView showTitle:responseObject.msg des:@"账号一经注销，资产清零，不可找回" buttonTitle:@"注销账号" buttonColor:[UIColor appGreenColor] buttonClick:^{
                    HNSH_GetAuthCodeAlert *alert = [[HNSH_GetAuthCodeAlert alloc]initWithFrame:CGRectMake(0, 0, 287, 220)];
                    [alert showView];
                } cancelButtonTitle:@"我再想想" cancelButtonColor:[UIColor appBGColor] cancelButtonClick:^{
                    
                }];
            }
        } Failure:^(NSError * _Nullable error) {
            
        }];
    }];
}

- (void)load {
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
